import { getOperationMpledgeDetailAPI } from "../../api/shesu";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // rightLine 右侧装饰线
    // bottomLine 底部装饰线
    // col 占位列数
    // style 值样式
    contentList: [
      {
        name: "动产抵押登记信息",
        list: [
          {
            key: "registerOffice",
            label: "登记机关",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "registerNo",
            label: "登记编号",
            value: "",
            rightLine: true,
            bottomLine: true,
          },
          {
            key: "debtSecuredAmount",
            label: "数额",
            value: "",
            bottomLine: true,
          },
          {
            key: "status",
            label: "状态",
            value: "",
            rightLine: true,
          },
          {
            key: "registerDate",
            label: "登记时间",
            value: "",
          },
        ],
      },
      {
        name: "抵押权人信息",
        list: [
          {
            key: "name",
            label: "抵押权人名称",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "companyName",
            label: "企业名称",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "identityType",
            label: "抵押权人证照类型",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "identityNo",
            label: "证照号码",
            value: "",
            col: 2,
            bottomLine: true,
          },
        ],
      },
      {
        name: "被担保主债权信息",
        list: [
          {
            key: "companyName",
            label: "企业名称",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "amount",
            label: "金额（万元）",
            value: "",
            rightLine: true,
            bottomLine: true,
            style: "color:#F04040",
          },
          {
            key: "kind",
            label: "种类",
            value: "",
            bottomLine: true,
          },
          {
            key: "assuranceScope",
            label: "担保范围",
            value: "",
            col: 2,
            bottomLine: true,
          },
          {
            key: "fulfillObligation",
            label: "履行义务",
            value: "",
            col: 2,
          },
        ],
      },
      {
        name: "抵押物信息",
        list: [
          {
            key: "name",
            label: "抵押物名称",
            value: "",
            col: 2,
          },
          {
            key: "ownership",
            label: "所有权或使用权归属",
            value: "",
            col: 2,
          },
          {
            key: "other",
            label: "数量、质量、状况、所在地等情况",
            value: "",
            col: 2,
          },
        ],
      },
      {
        name: "取消信息",
        list: [
          {
            key: "cancelReason",
            label: "种类",
            value: "",
            col: 2,
          },
          {
            key: "cancelDate",
            label: "取消时间",
            value: "",
            col: 2,
          },
        ],
      },
    ],
    id: "",
    info: "",
  },
  getDetail() {
    getOperationMpledgeDetailAPI({ id: this.data.id }).then((res: any) => {
      if (res.code === "000") {
        let operationMpledgeReq = res.content.operationMpledgeReq;
        let pledgeeReq = res.content.pledgeeReq;
        let guaranteedRightReq = res.content.guaranteedRightReq;
        let guaranteeReq = res.content.guaranteeReq;
        let cancelReq = res.content.cancelReq;

        this.data.contentList[0].list.forEach((item: any) => {
          if (operationMpledgeReq) {
            item.value = operationMpledgeReq[item.key];
            if (item.key === "status") {
              item.style =
                item.value === "有效" ? "color:#00AD65" : "color:#F04040";
            }
          }
        });
        this.data.contentList[1].list.forEach((item: any) => {
          if (pledgeeReq) {
            item.value = pledgeeReq[item.key];
          }
        });
        this.data.contentList[2].list.forEach((item: any) => {
          if (guaranteedRightReq) {
            item.value = guaranteedRightReq[item.key];
          }
        });
        this.data.contentList[3].list.forEach((item: any) => {
          if (guaranteeReq) {
            item.value = guaranteeReq[item.key];
          }
        });
        this.data.contentList[4].list.forEach((item: any) => {
          if (cancelReq) {
            item.value = cancelReq[item.key];
          }
        });
        this.setData({
          contentList: this.data.contentList,
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option: any) {
    this.setData({
      info: JSON.parse(option.info),
      id: JSON.parse(option.info).id,
    });
    this.getDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },
});
